package com.etc.miaosha.file;

import org.apache.commons.io.monitor.FileAlterationListener;
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @description:
 * @author: kalista
 * @time: 2019/11/13 17:15
 */
@Component
public class FileListenerExample implements FileAlterationListener {


    @Override
    public void onStart(FileAlterationObserver observer) {
        System.out.println("观察文件变化任务开始");
    }

    @Override
    public void onDirectoryCreate(File directory) {
        System.out.println("创建文件夹" + directory);
    }

    @Override
    public void onDirectoryChange(File directory) {
        System.out.println("修改文件夹" + directory);
    }

    @Override
    public void onDirectoryDelete(File directory) {
        System.out.println("删除文件夹" + directory);
    }

    @Override
    public void onFileCreate(File file) {
        System.out.println("创建文件" + file);
    }

    @Override
    public void onFileChange(File file) {
        System.out.println("修改文件" + file);
    }

    @Override
    public void onFileDelete(File file) {
        System.out.println("删除文件" + file);
    }

    @Override
    public void onStop(FileAlterationObserver observer) {
        System.out.println("观察文件变化任务结束");
    }
}
